using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Webadmin_Modules_User_UserBody : bzAdminUCBase
{
    public string _CateID = "";
    public DataTable _dt = new DataTable();
    public bzAdminUser bz = new bzAdminUser();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.initSiteLang(bzSiteOption.Group.Administrator,bzSiteOption.None,"UserList");        
    }
    private void delete()
    {
        if (this.AllowDelete)
        {

            string chk = Request.Form["Chk"] == null ? "-1" : Request.Form["Chk"].Replace(Session["AdminUser"].ToString(), "");
            int count = bz.deleteRecord(chk.Split(','));
            if (count < chk.Split(',').Length)
                Response.Write(bzStringClass.addStringAlert(this.AdminLang["ChildrenNotEmpty"]));
        }
        else Response.Redirect(bzStringClass.AlertPermission);
    }
    private void active(string act)
    {
        if (this.AllowEdit)
        {
            string chk = Request.Form["Chk"] == null ? "-1" : Request.Form["Chk"].Replace(Session["AdminUser"].ToString(), "");
            bz.activeRecord(chk.Split(','), act);
        }
        else Response.Redirect(bzStringClass.AlertPermission);
    }
    override protected void loadAction()
    {
        if (!IsPostBack)
        {
            this.loadFRMFilter();
            switch (this.Act)
            {
                case "Dis": this.active("0"); break;
                case "Ena": this.active("1"); break;
                case "Del": this.delete(); break;
            }
            this.showData();
        }
    }
    private void loadCate()
    {
        DataTable dtCate = new bzUserGroup().getTable("", "1", "-1", "-1");
        this.cboCategory.DataSource = dtCate;
        this.cboCategory.DataTextField = "GroupUser";
        this.cboCategory.DataValueField = "GroupUser";
        this.cboCategory.DataBind();
        this.cboCategory.Items.Insert(0, new ListItem(this.AdminLang["All"].ToString(), "-1"));

        
        this.cboCategory.SelectedValue =  string.IsNullOrEmpty(Request.QueryString["CateID"]) ? "-1" : Request.QueryString["CateID"];
    }
    private void loadFRMFilter()
    {
        this.loadCate();       

        this.cboFilterEnabled.Items.Add(new ListItem(this.AdminLang["All"].ToString(), "-1"));
        this.cboFilterEnabled.Items.Add(new ListItem(this.AdminLang["Enabled"].ToString(), "1"));
        this.cboFilterEnabled.Items.Add(new ListItem(this.AdminLang["Disabled"].ToString(), "0"));

        this.cboFilterEnabled.SelectedValue = Request.QueryString["Enabled"] == null ? "-1" : Request.QueryString["Enabled"];
        this.txtFilter.Text = Request.QueryString["Keyword"] == null ? "" : Request.QueryString["Keyword"];
        this.btnFilter.Text = this.AdminLang["Filter"].ToString();
    }
    protected void btnFilter_Click(object sender, EventArgs e)
    {
        this.showData();
    }
    private void showData()
    {
        this.SearchString = "&CateID=" + this.cboCategory.SelectedValue + "&Keyword=" + this.txtFilter.Text + "&Enabled=" + this.cboFilterEnabled.SelectedValue;
        this.loadPagination(bz.getTotal(this.txtFilter.Text.Replace('*', '%'), this.cboFilterEnabled.SelectedValue, this.cboCategory.SelectedValue), Convert.ToInt32(this.SiteOption["AdminLimit"]), "?" + this.SearchString);
        _dt = bz.getTable(this.txtFilter.Text.Replace('*', '%'), this.cboFilterEnabled.SelectedValue, this.cboCategory.SelectedValue, this.CurrentPage.ToString(), this.SiteOption["AdminLimit"].ToString());
        this.Navigator = this.AdminLang["MenuUser"] + "" + this.AdminLang["GeneralArrow"] + this.AdminLang["MenuUserList"];
        this.SearchString += "&Page=" + this.CurrentPage;
    }

}
